#include <iostream>
#include <vector>
#include "driver.hpp"

int main(int argc, char **argv)
{
	argagg::parser argparser{
		{{
			 "help",
			 {"-h", "--help"},
			 "Print help and exit",
			 0,
		 },
		 {"lex", {"-l", "--lex"}, "Directs it to run the lexer, but stop before parsing", 0},
		 {
			 "parse",
			 {"-p", "--parse"},
			 "Directs it to run the lexer and parser, but stop before assembly generation",
			 0,
		 },
		 {
			 "codegen",
			 {"-c", "--codegen"},
			 "Directs it to perform lexing, parsing and assembly generation, but stop before code emission",
			 0,
		 },
		 {
			"remove",
			{"-r", "--remove"},
			"remove tmp files",
			0,
		 },
		 {
			 "gcompile",
			 {"-g", "--gcompile"},
			 "use gcc compiler",
			 0,
		 }}};
	argagg::parser_results args;
	try
	{
		args = argparser.parse(argc, argv);
	}
	catch (const std::exception &e)
	{
	}

	if (args["remove"])
	{
		system("rm -rf *.i *.o");
		return 0;
	}

	std::vector<std::string> files;
	for (const auto &file : args.pos)
	{
		files.push_back(std::string(file));
		std::cout << "file: " << file << std::endl;
	}

	Driver::Driver driver(std::move(args), files);
	return driver.Run();
}
